using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using System.Runtime.InteropServices;
namespace PCSComMaterials.Inventory.DS
{
	public class IV_INSResultDS 
	{
		public IV_INSResultDS()
		{
		}
		private const string THIS = "PCSComMaterials.Inventory.DS.IV_INSResultDS";

		///    <summary>
		///       This method uses to add data to IV_INSResult
		///    </summary>
		///    <Inputs>
		///        IV_INSResultVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>


		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				IV_INSResultVO objObject = (IV_INSResultVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO IV_INSResult("
				+ IV_INSResultTable.INSPECTNO_FLD + ","
				+ IV_INSResultTable.POSTDATE_FLD + ","
				+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.REJECTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.SAMPLEQUANTITY_FLD + ","
				+ IV_INSResultTable.LOT_FLD + ","
				+ IV_INSResultTable.SERIAL_FLD + ","
				+ IV_INSResultTable.TRANTYPEID_FLD + ","
				+ IV_INSResultTable.MASTERLOCATIONID_FLD + ","
				+ IV_INSResultTable.CCNID_FLD + ","
				+ IV_INSResultTable.PRODUCTID_FLD + ","
				+ IV_INSResultTable.INSPECTORID_FLD + ","
				+ IV_INSResultTable.LOCATIONID_FLD + ","
				+ IV_INSResultTable.BINID_FLD + ","
				+ IV_INSResultTable.INSUMID_FLD + ","
				+ IV_INSResultTable.INSPECTIONSTATUS_FLD + ")"
				+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTNO_FLD].Value = objObject.InspectNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.POSTDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[IV_INSResultTable.POSTDATE_FLD].Value = objObject.PostDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.ACCEPTEDQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDQUANTITY_FLD].Value = objObject.AcceptedQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.REJECTEDQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.REJECTEDQUANTITY_FLD].Value = objObject.RejectedQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.SAMPLEQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.SAMPLEQUANTITY_FLD].Value = objObject.SampleQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.LOT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.LOT_FLD].Value = objObject.Lot;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.SERIAL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.SERIAL_FLD].Value = objObject.Serial;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.TRANTYPEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.TRANTYPEID_FLD].Value = objObject.TranTypeID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTORID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTORID_FLD].Value = objObject.InspectorID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.LOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.LOCATIONID_FLD].Value = objObject.LocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.BINID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.BINID_FLD].Value = objObject.BinID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSUMID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSUMID_FLD].Value = objObject.InsUMID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTIONSTATUS_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTIONSTATUS_FLD].Value = objObject.InspectionStatus;


				
				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

		/// <summary>
		/// Add the InsResult object and get returning id
		/// </summary>
		/// <param name="pobjObjectVO"></param>
		/// <returns></returns>
		public int AddAndReturnID(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".AddAndReturnID()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				IV_INSResultVO objObject = (IV_INSResultVO) pobjObjectVO;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				string strSql=	"INSERT INTO IV_INSResult("
					+ IV_INSResultTable.INSPECTNO_FLD + ","
					+ IV_INSResultTable.POSTDATE_FLD + ","
					+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + ","
					+ IV_INSResultTable.REJECTEDQUANTITY_FLD + ","
					+ IV_INSResultTable.SAMPLEQUANTITY_FLD + ","
					+ IV_INSResultTable.LOT_FLD + ","
					+ IV_INSResultTable.SERIAL_FLD + ","
					+ IV_INSResultTable.TRANTYPEID_FLD + ","
					+ IV_INSResultTable.MASTERLOCATIONID_FLD + ","
					+ IV_INSResultTable.CCNID_FLD + ","
					+ IV_INSResultTable.PRODUCTID_FLD + ","
					+ IV_INSResultTable.INSPECTORID_FLD + ","
					+ IV_INSResultTable.LOCATIONID_FLD + ","
					+ IV_INSResultTable.BINID_FLD + ","
					+ IV_INSResultTable.INSUMID_FLD + ","
					+ IV_INSResultTable.ACCEPTEDLOCID_FLD + ","
					+ IV_INSResultTable.ACCEPTEDBINID_FLD + ","
					+ IV_INSResultTable.REJECTEDLOCID_FLD + ","
					+ IV_INSResultTable.REJECTEDBINID_FLD + ","
					+ IV_INSResultTable.INSPECTIONSTATUS_FLD + ")"
					+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)  SELECT @@IDENTITY" ;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTNO_FLD].Value = objObject.InspectNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.POSTDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[IV_INSResultTable.POSTDATE_FLD].Value = objObject.PostDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.ACCEPTEDQUANTITY_FLD, OleDbType.Decimal));
				if (objObject.AcceptedQuantity != decimal.MinusOne)
				{
					ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDQUANTITY_FLD].Value = objObject.AcceptedQuantity;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDQUANTITY_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.REJECTEDQUANTITY_FLD, OleDbType.Decimal));
				if (objObject.RejectedQuantity != decimal.MinusOne)
				{
					ocmdPCS.Parameters[IV_INSResultTable.REJECTEDQUANTITY_FLD].Value = objObject.RejectedQuantity;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.REJECTEDQUANTITY_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.SAMPLEQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.SAMPLEQUANTITY_FLD].Value = objObject.SampleQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.LOT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.LOT_FLD].Value = objObject.Lot;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.SERIAL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.SERIAL_FLD].Value = objObject.Serial;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.TRANTYPEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.TRANTYPEID_FLD].Value = objObject.TranTypeID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTORID_FLD, OleDbType.Integer));
				if (objObject.InspectorID > 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.INSPECTORID_FLD].Value = objObject.InspectorID;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.INSPECTORID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.LOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.LOCATIONID_FLD].Value = objObject.LocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.BINID_FLD, OleDbType.Integer));
				if (objObject.BinID != 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.BINID_FLD].Value = objObject.BinID;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.BINID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSUMID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSUMID_FLD].Value = objObject.InsUMID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.ACCEPTEDLOCID_FLD, OleDbType.Integer));
				if (objObject.AcceptedLocID != 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDLOCID_FLD].Value = objObject.AcceptedLocID;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDLOCID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.ACCEPTEDBINID_FLD, OleDbType.Integer));
				if (objObject.AcceptedBinID != 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDBINID_FLD].Value = objObject.AcceptedBinID;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDBINID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.REJECTEDLOCID_FLD, OleDbType.Integer));
				if (objObject.RejectedLocID != 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.REJECTEDLOCID_FLD].Value = objObject.RejectedLocID;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.REJECTEDLOCID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.REJECTEDBINID_FLD, OleDbType.Integer));
				if (objObject.RejectedBinID != 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.REJECTEDBINID_FLD].Value = objObject.RejectedBinID;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.REJECTEDBINID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTIONSTATUS_FLD, OleDbType.Integer));
				if (objObject.InspectionStatus > 0)
				{
					ocmdPCS.Parameters[IV_INSResultTable.INSPECTIONSTATUS_FLD].Value = objObject.InspectionStatus;
				}
				else
				{
					ocmdPCS.Parameters[IV_INSResultTable.INSPECTIONSTATUS_FLD].Value = DBNull.Value;
				}
				
				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				object objResult = ocmdPCS.ExecuteScalar();	
				if ((objResult != null) && (objResult != DBNull.Value))
				{
					return int.Parse(objResult.ToString());
				}
				return 0;
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

		///    <summary>
		///       This method uses to add data to IV_INSResult
		///    </summary>
		///    <Inputs>
		///        IV_INSResultVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + IV_INSResultTable.TABLE_NAME + " WHERE  " + "InsResultID" + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}



			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

		///    <summary>
		///       This method uses to add data to IV_INSResult
		///    </summary>
		///    <Inputs>
		///        IV_INSResultVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
				+ IV_INSResultTable.INSRESULTID_FLD + ","
				+ IV_INSResultTable.INSPECTNO_FLD + ","
				+ IV_INSResultTable.POSTDATE_FLD + ","
				+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.REJECTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.SAMPLEQUANTITY_FLD + ","
				+ IV_INSResultTable.LOT_FLD + ","
				+ IV_INSResultTable.SERIAL_FLD + ","
				+ IV_INSResultTable.TRANTYPEID_FLD + ","
				+ IV_INSResultTable.MASTERLOCATIONID_FLD + ","
				+ IV_INSResultTable.CCNID_FLD + ","
				+ IV_INSResultTable.PRODUCTID_FLD + ","
				+ IV_INSResultTable.INSPECTORID_FLD + ","
				+ IV_INSResultTable.LOCATIONID_FLD + ","
				+ IV_INSResultTable.BINID_FLD + ","
				+ IV_INSResultTable.INSUMID_FLD + ","
				+ IV_INSResultTable.INSPECTIONSTATUS_FLD
				+ " FROM " + IV_INSResultTable.TABLE_NAME
				+" WHERE " + IV_INSResultTable.INSRESULTID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				IV_INSResultVO objObject = new IV_INSResultVO();

				while (odrPCS.Read())
				{ 
				objObject.InsResultID = int.Parse(odrPCS[IV_INSResultTable.INSRESULTID_FLD].ToString().Trim());
				objObject.InspectNo = odrPCS[IV_INSResultTable.INSPECTNO_FLD].ToString().Trim();
				objObject.PostDate = DateTime.Parse(odrPCS[IV_INSResultTable.POSTDATE_FLD].ToString().Trim());
				objObject.AcceptedQuantity = Decimal.Parse(odrPCS[IV_INSResultTable.ACCEPTEDQUANTITY_FLD].ToString().Trim());
				objObject.RejectedQuantity = Decimal.Parse(odrPCS[IV_INSResultTable.REJECTEDQUANTITY_FLD].ToString().Trim());
				objObject.SampleQuantity = Decimal.Parse(odrPCS[IV_INSResultTable.SAMPLEQUANTITY_FLD].ToString().Trim());
				objObject.Lot = odrPCS[IV_INSResultTable.LOT_FLD].ToString().Trim();
				objObject.Serial = odrPCS[IV_INSResultTable.SERIAL_FLD].ToString().Trim();
				objObject.TranTypeID = int.Parse(odrPCS[IV_INSResultTable.TRANTYPEID_FLD].ToString().Trim());
				objObject.MasterLocationID = int.Parse(odrPCS[IV_INSResultTable.MASTERLOCATIONID_FLD].ToString().Trim());
				objObject.CCNID = int.Parse(odrPCS[IV_INSResultTable.CCNID_FLD].ToString().Trim());
				objObject.ProductID = int.Parse(odrPCS[IV_INSResultTable.PRODUCTID_FLD].ToString().Trim());
				objObject.InspectorID = int.Parse(odrPCS[IV_INSResultTable.INSPECTORID_FLD].ToString().Trim());
				objObject.LocationID = int.Parse(odrPCS[IV_INSResultTable.LOCATIONID_FLD].ToString().Trim());
				objObject.BinID = int.Parse(odrPCS[IV_INSResultTable.BINID_FLD].ToString().Trim());
				objObject.InsUMID = int.Parse(odrPCS[IV_INSResultTable.INSUMID_FLD].ToString().Trim());
				objObject.InspectionStatus = int.Parse(odrPCS[IV_INSResultTable.INSPECTIONSTATUS_FLD].ToString().Trim());

				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		///    <summary>
		///       This method uses to add data to IV_INSResult
		///    </summary>
		///    <Inputs>
		///        IV_INSResultVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>
		
	
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			IV_INSResultVO objObject = (IV_INSResultVO) pobjObjecVO;
			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE IV_INSResult SET "
				+ IV_INSResultTable.INSPECTNO_FLD + "=   ?" + ","
				+ IV_INSResultTable.POSTDATE_FLD + "=   ?" + ","
				+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + "=   ?" + ","
				+ IV_INSResultTable.REJECTEDQUANTITY_FLD + "=   ?" + ","
				+ IV_INSResultTable.SAMPLEQUANTITY_FLD + "=   ?" + ","
				+ IV_INSResultTable.LOT_FLD + "=   ?" + ","
				+ IV_INSResultTable.SERIAL_FLD + "=   ?" + ","
				+ IV_INSResultTable.TRANTYPEID_FLD + "=   ?" + ","
				+ IV_INSResultTable.MASTERLOCATIONID_FLD + "=   ?" + ","
				+ IV_INSResultTable.CCNID_FLD + "=   ?" + ","
				+ IV_INSResultTable.PRODUCTID_FLD + "=   ?" + ","
				+ IV_INSResultTable.INSPECTORID_FLD + "=   ?" + ","
				+ IV_INSResultTable.LOCATIONID_FLD + "=   ?" + ","
				+ IV_INSResultTable.BINID_FLD + "=   ?" + ","
				+ IV_INSResultTable.INSUMID_FLD + "=   ?" + ","
				+ IV_INSResultTable.INSPECTIONSTATUS_FLD + "=  ?"
				+" WHERE " + IV_INSResultTable.INSRESULTID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTNO_FLD].Value = objObject.InspectNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.POSTDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[IV_INSResultTable.POSTDATE_FLD].Value = objObject.PostDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.ACCEPTEDQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.ACCEPTEDQUANTITY_FLD].Value = objObject.AcceptedQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.REJECTEDQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.REJECTEDQUANTITY_FLD].Value = objObject.RejectedQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.SAMPLEQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_INSResultTable.SAMPLEQUANTITY_FLD].Value = objObject.SampleQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.LOT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.LOT_FLD].Value = objObject.Lot;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.SERIAL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_INSResultTable.SERIAL_FLD].Value = objObject.Serial;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.TRANTYPEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.TRANTYPEID_FLD].Value = objObject.TranTypeID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTORID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTORID_FLD].Value = objObject.InspectorID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.LOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.LOCATIONID_FLD].Value = objObject.LocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.BINID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.BINID_FLD].Value = objObject.BinID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSUMID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSUMID_FLD].Value = objObject.InsUMID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSPECTIONSTATUS_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSPECTIONSTATUS_FLD].Value = objObject.InspectionStatus;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_INSResultTable.INSRESULTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_INSResultTable.INSRESULTID_FLD].Value = objObject.InsResultID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}


		///    <summary>
		///       This method uses to add data to IV_INSResult
		///    </summary>
		///    <Inputs>
		///        IV_INSResultVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();
			
		

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
				+ IV_INSResultTable.INSRESULTID_FLD + ","
				+ IV_INSResultTable.INSPECTNO_FLD + ","
				+ IV_INSResultTable.POSTDATE_FLD + ","
				+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.REJECTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.SAMPLEQUANTITY_FLD + ","
				+ IV_INSResultTable.LOT_FLD + ","
				+ IV_INSResultTable.SERIAL_FLD + ","
				+ IV_INSResultTable.TRANTYPEID_FLD + ","
				+ IV_INSResultTable.MASTERLOCATIONID_FLD + ","
				+ IV_INSResultTable.CCNID_FLD + ","
				+ IV_INSResultTable.PRODUCTID_FLD + ","
				+ IV_INSResultTable.INSPECTORID_FLD + ","
				+ IV_INSResultTable.LOCATIONID_FLD + ","
				+ IV_INSResultTable.BINID_FLD + ","
				+ IV_INSResultTable.INSUMID_FLD + ","
				+ IV_INSResultTable.INSPECTIONSTATUS_FLD
					+ " FROM " + IV_INSResultTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,IV_INSResultTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
   				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}


		}


		///    <summary>
		///       This method uses to add data to IV_INSResult
		///    </summary>
		///    <Inputs>
		///        IV_INSResultVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>
		
		public void UpdateDataSet(DataSet pdstData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql=	"SELECT "
				+ IV_INSResultTable.INSRESULTID_FLD + ","
				+ IV_INSResultTable.INSPECTNO_FLD + ","
				+ IV_INSResultTable.POSTDATE_FLD + ","
				+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.REJECTEDQUANTITY_FLD + ","
				+ IV_INSResultTable.SAMPLEQUANTITY_FLD + ","
				+ IV_INSResultTable.LOT_FLD + ","
				+ IV_INSResultTable.SERIAL_FLD + ","
				+ IV_INSResultTable.TRANTYPEID_FLD + ","
				+ IV_INSResultTable.MASTERLOCATIONID_FLD + ","
				+ IV_INSResultTable.CCNID_FLD + ","
				+ IV_INSResultTable.PRODUCTID_FLD + ","
				+ IV_INSResultTable.INSPECTORID_FLD + ","
				+ IV_INSResultTable.LOCATIONID_FLD + ","
				+ IV_INSResultTable.BINID_FLD + ","
				+ IV_INSResultTable.INSUMID_FLD + ","
				+ IV_INSResultTable.INSPECTIONSTATUS_FLD 
				+ "  FROM " + IV_INSResultTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pdstData.EnforceConstraints = false;
				odadPCS.Update(pdstData,IV_INSResultTable.TABLE_NAME);

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}

		/// <summary>
		/// Get information for the InsResult by ID
		/// </summary>
		/// <param name="pintInsResultID"></param>
		/// <returns></returns>
		public DataRow GetInsResultInforbyID(int pintInsResultID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
					+ IV_INSResultTable.INSPECTNO_FLD + ","
					+ IV_INSResultTable.POSTDATE_FLD + ","
					+ IV_INSResultTable.ACCEPTEDQUANTITY_FLD + ","
					+ IV_INSResultTable.REJECTEDQUANTITY_FLD + ","
					+ IV_INSResultTable.SAMPLEQUANTITY_FLD + ","
					+ IV_INSResultTable.LOT_FLD + ","
					+ IV_INSResultTable.SERIAL_FLD + ","
					+ "(SELECT " + MST_MasterLocationTable.CODE_FLD + " FROM " + MST_MasterLocationTable.TABLE_NAME + " WHERE " + MST_MasterLocationTable.MASTERLOCATIONID_FLD + " = INS." + IV_INSResultTable.MASTERLOCATIONID_FLD + ") as " + MST_MasterLocationTable.TABLE_NAME + MST_MasterLocationTable.CODE_FLD + ","
					+ "(SELECT " + MST_LocationTable.CODE_FLD + " FROM " + MST_LocationTable.TABLE_NAME + " WHERE " + MST_LocationTable.LOCATIONID_FLD + " = INS." + IV_INSResultTable.LOCATIONID_FLD + ") as " + MST_LocationTable.TABLE_NAME + MST_LocationTable.CODE_FLD + ","
					+ "(SELECT " + MST_BINTable.CODE_FLD + " FROM " + MST_BINTable.TABLE_NAME + " WHERE " + MST_BINTable.BINID_FLD + " = INS." + IV_INSResultTable.BINID_FLD + ") as " + MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD + ","
					+ "(SELECT " + MST_LocationTable.CODE_FLD + " FROM " + MST_LocationTable.TABLE_NAME + " WHERE " + MST_LocationTable.LOCATIONID_FLD + " = INS." + IV_INSResultTable.ACCEPTEDLOCID_FLD + ") as " + MST_LocationTable.TABLE_NAME + MST_LocationTable.CODE_FLD + 1.ToString() + ","
					+ "(SELECT " + MST_BINTable.CODE_FLD + " FROM " + MST_BINTable.TABLE_NAME + " WHERE " + MST_BINTable.BINID_FLD + " = INS." + IV_INSResultTable.ACCEPTEDBINID_FLD + ") as " + MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD + 1.ToString() + ","
					+ "(SELECT " + MST_LocationTable.CODE_FLD + " FROM " + MST_LocationTable.TABLE_NAME + " WHERE " + MST_LocationTable.LOCATIONID_FLD + " = INS." + IV_INSResultTable.REJECTEDLOCID_FLD + ") as " + MST_LocationTable.TABLE_NAME + MST_LocationTable.CODE_FLD + 2.ToString() + ","
					+ "(SELECT " + MST_BINTable.CODE_FLD + " FROM " + MST_BINTable.TABLE_NAME + " WHERE " + MST_BINTable.BINID_FLD + " = INS." + IV_INSResultTable.REJECTEDBINID_FLD + ") as " + MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD + 2.ToString() + ","
					+ IV_INSResultTable.INSPECTIONSTATUS_FLD + ","
					+ IV_INSResultTable.PRODUCTID_FLD
					+ " FROM  " + IV_INSResultTable.TABLE_NAME + " as INS"
					+ " WHERE INS." + IV_INSResultTable.INSRESULTID_FLD + "=" + pintInsResultID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, IV_INSResultTable.TABLE_NAME);
				if (dstPCS.Tables[0].Rows.Count > 0) 
				{
					return dstPCS.Tables[0].Rows[0];
				}
				else 
					return null;
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	}
}
